﻿<!DOCTYPE html>
<html>
<head>
    <title>CGI</title>
</head>
<body>
    <h1>Our Page</h1>
    <script>
        //01 window global object
        //outside the function, all var teat as global variable
        //by this keyword, we can also call global variable
        
        var productId = 'PRD-2000';
        console.log(productId);
        console.log(window.productId);
        console.log(this === window);
        console.log(this.productId);
        

        //02 empty object
        //when function run, description var still in global scope and not in function scope
        /*
        var description = 'hardware product';
        function updateProduct() {
            description = 'updated product';
        }
        updateProduct();
        console.log(description);
        */

        //03
        //description is declared without var, hence it will create in global scope
        //'use strict'; is use to avoid polution within global namespace
        /*
        //'use strict';
        function updateProduct() {
            description = 'updated product';
        }
        updateProduct();
        console.log(description);
        */
    </script>
</body>
</html>